package com.csw.android.dev_utils.ex

import android.app.Activity
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import com.csw.android.dev_utils.ui.CommonActivity

object ActivityEx {

    /**
     * 绑定ViewModel
     */
    inline fun <reified V : ViewModel> ComponentActivity.bindVM(): V {
        return ViewModelProvider(this).get(V::class.java)
    }

    /**
     * 通过通用Activity打开Fragment
     */
    inline fun <reified V : Fragment> Activity.openInCommonActivity(data: Bundle? = null) {
        CommonActivity.openActivity(this, V::class.java, data)
    }


    /**
     * 通过通用Activity打开Fragment
     */
    fun <T : Fragment> Activity.openInCommonActivity(
        fragmentClass: Class<T>,
        data: Bundle? = null
    ) {
        CommonActivity.openActivity(this, fragmentClass, data)
    }
}